home *** CD-ROM | disk | FTP | other *** search
- Path: news.netam.net!alpha!bgc
- From: bgc@alpha.netam.net (The Bowling Green Connection)
- Newsgroups: comp.lang.c
- Subject: Can you printf a long
- Date: 3 Apr 1996 16:24:33 GMT
- Organization: NetAmerica, Bowling Green, KY.
- Message-ID: <4ju8o1$dc3@news.netam.net>
- NNTP-Posting-Host: alpha.netam.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- I had some trouble with this code:
- (I'm using gcc on Digital Unix)
-
- int main() {
- long i;
-
- while(1) {
- i++;
- printf("%f\n", i);
- }
-
- return 0;
- }
-
- The numbers printed to the screen as 0.00000.
- (Nevermind that this is an infinite loop--I was piping the output to
- a file which made me run out of disk space. This is just for testing)
-
- But when I changed %f to %d, the numbers printed correctly.
- I thought that %d had the same limitations as an int..that is,
- it could only print about 4 bits of information, whereas a long
- is capable of more (8 or 16 bits), so wouldn't %f (float) be able
- to better handle those long numbers? And why did %d work
- correctly, even up to 634,000 (that's when my disk space ran out.. :))
-
- Well, then I changed the "long i" declaration to "int i", and changed %f
- to %d, and I got the SAME results! The numbers went up to 634,000!
- I didn't think an int could handle this much!
-
- Another strange thing is, I did a sizeof(int) and a sizeof(long), and they
- BOTH returned a 4!!! That can't be right, can it??!
-
- _______________________________bgc@bgcky.com___________________________________
- Edgar E. Easterly, IV http://www.bgcky.com Bowling Green, Kentucky -=O=-
- "Except the Lord build thy house, ye labour in vain that build it; Except *
- the Lord keep thy city, the watchman will awake but in vain." Psalms 127:1 |
-